package com.roden.study.java;

import org.junit.Test;

import java.lang.reflect.Method;

/**
 * @Author luod
 * @create 2022/5/18 11:26
 * 
 * 
 * NoSuchMethodException occurs when you try to invoke a method using reflection. 
 * NoSuchMethodError occurs when you had that method while compiling but dont have it during the runtime.
 * 
 * Compile it using javac ExceptionTest.java And now try to run this using java ExceptionTest
 *
 * It ll give you
 *
 * java.lang.NoSuchMethodError: main
 * Exception in thread "main"
 * 
 * Because it tries to find the public static void main(String [] args) which is not there
 * 
 */
public class ExceptionTest {
    
    /**
     * this is ll throw an exception saying
     * java.lang.NoSuchMethodException: java.lang.String.myMethod(null, null)
     */
    @Test
    public void NoSuchMethodException() throws ClassNotFoundException, NoSuchMethodException {
        Class c = Class.forName("java.lang.String");
        Class[] paramTypes = new Class[2];
        Method m = c.getDeclaredMethod("myMethod", paramTypes);        
    }
}
